package club.fuwenhao.config;

import club.fuwenhao.bean.DemoData;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.excel.read.listener.ReadListener;
import org.ehcache.impl.internal.classes.commonslang.ArrayUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @program: fwh-excel
 * @description:
 * @author: fwh
 * @date: 2021-12-31 11:51
 **/
public class UserExcelListener extends AnalysisEventListener<DemoData> {
    /**
     * 批处理阈值
     */
    private static final int BATCH_COUNT = 2;
    List<DemoData> list = new ArrayList<DemoData>(BATCH_COUNT);

    @Override
    public void invoke(DemoData demoData, AnalysisContext analysisContext) {
        System.out.println(demoData.toString());
//        log.info("解析到一条数据:{}", JSON.toJSONString(user));
        list.add(demoData);
//        if (list.size() >= BATCH_COUNT) {
//            saveData();
//            list.clear();
//        }
//        System.out.println(list);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }
}
